<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 数组转对象
    /*
      for循环遍历数组：
        .如果obj中存在arr[i] 就让 obj的value++
        如果不存在arr[i],就添加 obj[i] = 1；
    */
    var arr = ['a', 'a', 'a', 'b', 'b', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'd'];
    function toObj(arr) {
      var obj = {};
      var n = 1;
      for (var i = 0; i < arr.length; i++) {
        if (obj[arr[i]]) {
          obj[arr[i]]++;
        } else {
          obj[arr[i]] = 1;
        }
      }
      return obj

    }
    console.log(toObj(arr));

  </script>
</body>

</html>